package com.chuangjiangx.member.common;

import lombok.Getter;

import java.util.concurrent.TimeUnit;

/**
 * Created by zhou on 2017/6/14.
 * 全局常量类
 */
public class Constants {

    public static final TimeUnit APP_TOKEN_TIME_UNIT = TimeUnit.DAYS;

    public static final int BASE_TOKEN_TIMEOUT = 30;

    //登录错误次数
    public static final String REDIS_LOGIN_ERRORS_SUFFIX_KEY = "_MERCHANT_ERROR";

    //15分钟内第一次登录错误时间
    public static final String REDIS_FIRST_ERROR_TIME_SUFFIX_KEY = "_MERCHANT_ERROR_TIME";

    //账号锁定时间
    public static final String REDIS_LOCK_KEY_SUFFIX_KEY = "_MERCHANT_LOCKED";

    //验证码key
    public static final String REDIS_KCAPTCHA_KEY = "MERCHANT_KCAPTCHA_";

    //权限key
    public static final String REDIS_COMPONENLIST_KEY = "COMPONENLIST-";

    //当前登录用户
    public static final String CURRENT_LOGIN_USER_KEY = "current_login_user_key";

    //登陆异常描述信息
    public static final String USERNAME_OR_PASSWORD_ERROR = "用户名或密码错误";
    public static final String KCAPTCHA_ERROR = "验证码错误";
    public static final String KCAPTCHA_INVALID = "验证码过期";
    public static final String LOCKED_ERROR = "账号已锁定，请30分钟后再尝试";
    public static final String ATTEMPT_LIMIT = "%s,您还可以尝试%s次";
    public static final String GENERATE_ERROR = "请求失败,请重试";

    /**
     * 交易类型
     */
    @Getter
    public enum TradeType {
        PAYMENT("收款", "1"),
        REFUND("退款", "2"),
        TRANSFER("转账", "3");
        TradeType(String name, String code) {
            this.name = name;
            this.code = code;
        }
        private String name;
        private String code;

        public static TradeType getByCode(String code) {
            for (TradeType type : TradeType.values()) {
                if (type.code.equals(code)) {
                    return type;
                }
            }
            return null;
        }
    }

    /**
     * 语音播报开关
     */
    @Getter
    public enum SoundSwitch {
        CLOSE("关", "0"),
        OPEN("开", "1");
        SoundSwitch(String name, String code) {
            this.name = name;
            this.code = code;
        }
        private String name;
        private String code;
    }
}
